home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2144 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  78 lines

  1. Path: mrnews.mro.dec.com!news
  2. From: Hussein Salem <salem@ehvvs5.nwg.dec.com>
  3. Newsgroups: comp.lang.c
  4. Subject: directory functions ...
  5. Date: Fri, 19 Jan 1996 13:42:54 +0100
  6. Organization: Digital Equipment SIB
  7. Message-ID: <30FF91CE.3F54@ehvvs5.nwg.dec.com>
  8. NNTP-Posting-Host: ehvvs5.nwg.dec.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b5 (X11; I; OSF1 V3.0 alpha)
  13.  
  14. Hi,
  15.  
  16. I'm trying to make a small program in C handling a directory. open it and print it's content
  17. :
  18.  
  19.  
  20. The problem is it can't read it ! Why ? I 've set the mode to a+rwx to that direstory !
  21.  
  22. These are the code and if you know what's the problem please tell me why ?
  23.  
  24. -----------------
  25.  
  26. #include <stdio.h>
  27. #include <dirent.h>
  28. #include <sys/types.h>
  29. #define MYMAX   14
  30.  
  31. typedef struct {
  32.         long ino;
  33.         char name[MYMAX+1];
  34. } Dirent;
  35.  
  36. main(int argc,char **argv){
  37. char name[MYMAX];
  38. DIR     *dfd;
  39. char *dir;
  40. Dirent  *dp;
  41.  
  42. dir = "/usr/users/salem/test";
  43.  
  44. if ((dfd = opendir(dir) == NULL)) {
  45.         fprintf(stderr," can't open %s\n",dir);
  46.         return;
  47. }
  48. printf("dir opened %s\n",dir);
  49. if ( (dp = readdir(dfd)) == NULL) {
  50. fprintf(stderr," can't read %s\n",dir);return;
  51. }
  52. while ( (dp = readdir(dfd)) != NULL) {
  53.         printf("name = %s",dp->name);
  54.         /*if ( !strcmp(dp->name,argv[1]) || !strcmp(dp->name,"..") ) continue;
  55.         printf("name = %s/%s \n",dir, dp->name); */
  56. }
  57. closedir(dfd);
  58.  
  59.  
  60. }
  61. -- 
  62.                                                            ,,,
  63.                                                           (. .)
  64. _______________________________________________________ooO-(_)-Ooo______
  65. Hussein SALEM    (Digital Equipment B.V.)    | 
  66. Backenmonde 2                    | 
  67. 3434 kk Nieuwegein                | 
  68. Netherlands                    | "One day, I'll fly away"    
  69. Tel : (31) 30 6053725 (Home)            |
  70. Tel : (31) 30 6088719 (Work)            |    Coco-Wawa
  71. E-mail : salem_h@cecamo.enet.dec.com (Work)    |
  72. E-mail : salem@uto.mts.dec.com (digital)    |
  73. ______________________________________________________________Oooo._____
  74.                                                      .oooO    (   )
  75.                                                      (   )     ) /
  76.                                                       \ (     (_/
  77.                                                        \_)
  78.